package com.easy.goods.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.easy.bean.ProductImage;
import com.easy.bean.Products;
import com.easy.goods.mapper.Productdao;
import com.easy.goods.mapper.Productimagedao;
import com.easy.goods.service.ProductService;

@Service
public class ProductServiceImpl extends ServiceImpl<Productdao, Products> implements ProductService {
   @Autowired
   private Productdao productdao;
    @Autowired
   private Productimagedao imageD;
   
	public List<Products> getProductByCategoryID(IPage<Products> page,int categoryid){
		QueryWrapper<Products> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("categoryid",categoryid);
        List<Products> result=this.list(page,queryWrapper);
        return result;
	}

    @Override
    public Products getProductByID(int id) {
        Products result=this.getById(id);
        QueryWrapper<ProductImage> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("productid",id);
        List<ProductImage> list=imageD.selectList(queryWrapper);
        result.setImgList(list);
        return result;
    }
//    @Override
//    public List<Products> getProducts(int count, Products products) {
//        return null;
//    }
//
//    @Override
//    public Products getProductById(Integer id) {
//        return null;
//    }
//
//    @Override
//    public int postproduct(Products products) {
//        return 0;
//    }
//
//    @Override
//    public int updateproduct(Products products) {
//        return 0;
//    }

    @Override
    public int deleteproduct(Integer id) {
        return productdao.deleteById(id);

    }

//    @Override
//    public int decrystock(Integer id, Integer num) {
//        return 0;
//    }
//
//    @Override
//    public int editstock(Integer id, Integer num) {
//        return 0;
//    }
//
//    @Override
//    public int checkstock(Integer id, Integer num) {
//        return 0;
//    }
//
//    @Override
//    public IPage selectPage(Page page, Wrapper queryWrapper) {
//        return  productdao.selectPage(page,null);
//    }

    @Override
    public void updateshangxiajia(Integer id) {
Products products=productdao.selectById(id);
        System.out.println("----------");
String stutus=products.getIsactive().equals("1")?"0":"1";
products.setIsactive(stutus);
 productdao.updateById(products);
    }

   

//@Autowired
//private Productdao productdao;

//    @Override
//    public Products getProduct(Products products) {
//        return productdao.;
//
//    }
//
//    @Override
//    public int postproduct(Products products) {
//        return  productdao.insert(products);
//    }
//
//    @Override
//    public int updateproduct(Products products) {
//        return  productdao.updateById(products);
//    }
//

}
